<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * @access private
 * @desc generate password
 * @return string 
 * @author Mina Gerges
 */
class RandomGenerator {

    static function generatePassword($plength=6, $pnumberOnly=0) {

        list($_usec, $_sec) = explode(' ', microtime());
        srand((float) $_sec + ((float) $_usec * 100000));
        $validchars = "0123456789";
        if (!$pnumberOnly) {
            $validchars .= "abcdefghigklmnopqrstuwxyz";
        }

        $_password = "";
        $_counter = 0;

        while ($_counter < $plength) {
            $actChar = substr($validchars, rand(0, strlen($validchars) - 1), 1);

            // All character must be different
            if (!strstr($_password, $actChar)) {
                $_password .= $actChar;
                $_counter++;
            }
        }

        return $_password;
    }

}

?>
